/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.collection;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author VANDH
 */
public class DemoArrayList {

    private static ArrayList dogList = new ArrayList();
    private static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
        int choice;

        do {
            System.out.println("1. Thêm một con vật");
            System.out.println("2. Xóa con vật");
            System.out.println("3. In ra các con vật đang lưu");
            System.out.println("4. Thoát");
            choice = keyboard.nextInt();

            switch (choice) {
                case 1:
                    addDog();
                    break;
                case 2:
                    removeDog();
                    break;
                case 3:
                    listAllDog();
                    break;

            }
        } while (choice != 4);
    }

    private static void addDog() {
        int age;
        do {
            System.out.printf("Tên, tuổi con thứ %d : ", dogList.size() + 1);
            String name = keyboard.next();
            age = keyboard.nextInt();

            if (age != -1) {
                dogList.add(new Dog(name, age));
            }
        } while (age != -1);
    }

    private static void removeDog() {
        System.out.println("Tên con muốn xóa : ");
        String name = keyboard.next();

        for (int i = 0; i < dogList.size(); i++) {
            Dog dog = (Dog) dogList.get(i);

            if (dog.getName().equals(name)) {
                dogList.remove(i);
                i--;
            }
        }
    }

    private static void listAllDog() {
        for (Object i : dogList) {
            Dog d = (Dog) i;
            System.out.println(d.toString());

//            if (d.getName().equals("a")) {
//                dogList.remove(d);
//            }
        }
    }
}
